package com.lanxiaoye.shoppingSystem.service.impl;

import com.lanxiaoye.shoppingSystem.common.EncryptUtil;
import com.lanxiaoye.shoppingSystem.common.exception.BaseException;
import com.lanxiaoye.shoppingSystem.common.exception.EmptyException;
import com.lanxiaoye.shoppingSystem.dao.HomeRegisterMapper;
import com.lanxiaoye.shoppingSystem.dao.UserMapper;
import com.lanxiaoye.shoppingSystem.entity.User;
import com.lanxiaoye.shoppingSystem.service.HomeRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by libing on 2016/12/13.
 */
@Service
public class HomeRegisterServiceImpl implements HomeRegisterService {

    @Autowired
    HomeRegisterMapper homeRegisterMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public int checkExist(User user) throws EmptyException, BaseException  {
        try {
            if (user == null)
                throw new EmptyException("[HomeRegisterServiceImpl][checkExist] user empty");
            return homeRegisterMapper.checkExist(user);
        }catch (EmptyException e){
            throw new EmptyException(e.getMessage());
        }catch (BaseException e){
            throw new BaseException("[HomeRegisterServiceImpl][checkExist] exception");
        }

    }

    @Override
    public int checkExistByName(String name) {
        int result = userMapper.checkByName(name);
        return result;
    }

    @Override
    public int checkExistByPhone(String phone) {
        int result = userMapper.checkByPhone(phone);
        return result;
    }

    @Override
    public int checkExistByEmail(String email) {
        int result = userMapper.checkByEmail(email);
        return result;
    }

    @Override
    public int registerUser(User user){
        return userMapper.insertSelective(user);
    }

}
